<?php
namespace App\Logics;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\AttrValModel;

//逻辑处理
class AttrValLogic extends BaseLogic {


    public function __construct()
    {
        parent::__construct();

    }


    public static function getListByAttrId(int $attr_id,$fields=['*']){
        $data= AttrValModel::where('attr_id',$attr_id)->select($fields)->get();
        return ob_to_array($data);
    }

    public static function getListByAttrIds(array $attr_ids,$fields=['*']){
        $data= AttrValModel::whereIn('attr_id',$attr_ids)->select($fields)->get();
        return ob_to_array($data);
    }

    /** 根据商品id获取属性值
     * @param int $goods_id
     * @return mixed
     */
    public static function  getAttrValByGoodsId(int $goods_id){
        $attr_val=AttrValModel::join('attr_type as t','attr_val.attr_id','=','t.attr_id')
            ->select('attr_val.attr_id','attr_val.attr_name','t.attr_type','attr_val.id')
            ->where('t.goods_id',$goods_id)->get();
        return ob_to_array($attr_val);
    }







}
